﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.ComponentModel;
using Legend.Reflection;
using System.Reflection;

namespace Legend.Web.QueryString.Tests
{
    [TestFixture]
    public class SerializableMemberInfoCollectionTests
    {
        [Test, ExpectedException(typeof(ArgumentNullException))]
        public virtual void Constructor_throws_when_specified_enumerable_is_null()
        {
            var collection = new SerializableMemberInfoCollection(null);
        }

        [Test, ExpectedException(typeof(KeyNotFoundException), ExpectedMessage = "The specified member 'bar' does not exist.")]
        public virtual void indexer_throws_when_member_does_not_exist()
        {
            var collection = this.CreateCollection(this.CreateFakeMemberInfo("foo"));
            var member = collection["bar"];
        }

        [Test]
        public void Contains_returns_true_if_a_parameter_with_the_specified_name_exists_in_the_collection()
        {
            var collection = this.CreateCollection(this.CreateFakeMemberInfo("foo"));
            Assert.IsTrue(collection.Contains("foo"));
        }

        [Test]
        public void Contains_returns_false_if_a_parameter_with_the_specified_name_does_not_exist_in_the_collection()
        {
            var collection = this.CreateCollection(this.CreateFakeMemberInfo("bar"));
            Assert.IsFalse(collection.Contains("foo"));
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void Contains_throws_if_memberName_is_null()
        {
            var collection = this.CreateCollection();
            collection.Contains(null);
        }

        private SerializableMemberInfoCollection CreateCollection(params SerializableMemberInfo[] memberInfos)
        {
            return new SerializableMemberInfoCollection(memberInfos);
        }

        private SerializableMemberInfo CreateFakeMemberInfo(string memberName)
        {
            return new SerializableMemberInfo(memberName, new StringConverter(), null, 0);
        }
    }
}
